/*
 * SongInfoDialog.java
 *
 * Created on April 8, 2006, 11:59 AM
 */
package com.bff.slimserver.musicjukebox.ui.components.podcast;

import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import com.bff.slimserver.musicjukebox.ui.PodcastPanel;
import com.bff.bjj.ui.component.BJJButton;
import com.bff.bjj.utils.Utils;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bff.slimserver.SlimPlaylist;
import org.bff.slimserver.SlimPodcaster;
import org.bff.slimserver.exception.SlimConnectionException;
import org.bff.slimserver.exception.SlimException;
import org.bff.slimserver.musicobjects.SlimPodcastAudioDetails;

/**
 *
 * @author  Bill
 */
public class PodcastInfoDialog extends javax.swing.JDialog {

    private SlimPodcastAudioDetails podcast;
    private SlimPodcaster podcaster;
    private SlimPlaylist playlist;

    /** Creates new form SongInfoDialog */
    public PodcastInfoDialog(java.awt.Frame parent, boolean modal, SlimPodcastAudioDetails podcast) {
        super(parent, modal);
        this.podcast = podcast;

        try {
            setPodcaster(JukeboxProperties.getInstance().getPodcaster());
        } catch (SlimConnectionException ex) {
            Logger.getLogger(PodcastInfoDialog.class.getName()).log(Level.SEVERE, null, ex);
        }

        initComponents();

        Utils.centerInParent(this, parent);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnPanel = new javax.swing.JPanel();
        btnAddToPlaylist = new BJJButton();
        btnPlayNext = new BJJButton();
        btnClearAndPlay = new BJJButton();
        btnDone = new BJJButton();
        podcastInfoPanel = new PodcastInfoPanel(podcast, JukeboxProperties.getInstance().isShowCoverArt());

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Podcast Info");
        setMinimumSize(new java.awt.Dimension(500, 55));

        btnPanel.setBackground(java.awt.Color.lightGray);

        btnAddToPlaylist.setText("Add to Playlist");
        btnAddToPlaylist.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddToPlaylistActionPerformed(evt);
            }
        });
        btnPanel.add(btnAddToPlaylist);

        btnPlayNext.setText("Play Next");
        btnPlayNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPlayNextActionPerformed(evt);
            }
        });
        btnPanel.add(btnPlayNext);

        btnClearAndPlay.setText("Clear and Play");
        btnClearAndPlay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnClearAndPlayActionPerformed(evt);
            }
        });
        btnPanel.add(btnClearAndPlay);

        btnDone.setText("Done");
        btnDone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDoneActionPerformed(evt);
            }
        });
        btnPanel.add(btnDone);

        getContentPane().add(btnPanel, java.awt.BorderLayout.SOUTH);
        getContentPane().add(podcastInfoPanel, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnDoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDoneActionPerformed
        dispose();
    }//GEN-LAST:event_btnDoneActionPerformed

    private void btnAddToPlaylistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddToPlaylistActionPerformed
        this.setCursor(Utils.getHourglassCursor());
        try {
            try {
                getPlaylist().addPluginItem(podcast);
            } catch (SlimException ex) {
                Logger.getLogger(PodcastPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        } finally {
            this.setCursor(Utils.getNormalCursor());
        }
}//GEN-LAST:event_btnAddToPlaylistActionPerformed

    private void btnPlayNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPlayNextActionPerformed
        this.setCursor(Utils.getHourglassCursor());
        try {
            try {
                getPlaylist().insertPluginItem(podcast);
            } catch (SlimException ex) {
                Logger.getLogger(PodcastInfoDialog.class.getName()).log(Level.SEVERE, null, ex);
            }
        } finally {
            this.setCursor(Utils.getNormalCursor());
        }
}//GEN-LAST:event_btnPlayNextActionPerformed

    private void btnClearAndPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearAndPlayActionPerformed
        this.setCursor(Utils.getHourglassCursor());
        try {
            try {
                getPlaylist().playPluginItem(podcast);
            } catch (SlimException ex) {
                Logger.getLogger(PodcastInfoDialog.class.getName()).log(Level.SEVERE, null, ex);
            }
        } finally {
            this.setCursor(Utils.getNormalCursor());
        }
}//GEN-LAST:event_btnClearAndPlayActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddToPlaylist;
    private javax.swing.JButton btnClearAndPlay;
    private javax.swing.JButton btnDone;
    private javax.swing.JPanel btnPanel;
    private javax.swing.JButton btnPlayNext;
    private com.bff.slimserver.musicjukebox.ui.components.podcast.PodcastInfoPanel podcastInfoPanel;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the podcaster
     */
    public SlimPodcaster getPodcaster() {
        return podcaster;
    }

    /**
     * @param podcaster the podcaster to set
     */
    public void setPodcaster(SlimPodcaster podcaster) {
        this.podcaster = podcaster;
    }

    /**
     * @return the playlist
     */
    public SlimPlaylist getPlaylist() {
        return playlist;
    }

    /**
     * @param playlist the playlist to set
     */
    public void setPlaylist(SlimPlaylist playlist) {
        this.playlist = playlist;
    }
}
